<?php
namespace app\index\controller;

use app\index\model\Cate;
use app\index\model\Brand;
use think\Controller;
use think\Request;

class Base extends Controller {

    public function _initialize(){
        //行业分类导航
        $cateModel = new Cate();
        $cateInfo = $cateModel -> getCateList(['pid'=>0,'status'=>1],'id asc',4);
        $this -> assign('cateInfo',$cateInfo);
        //推荐到头部的品牌
        $cid = $this -> request -> param('cid');
        if($cid){
           $where['cate_pid'] = $cid;
        }
        $where['reco_header'] = 1;
        $where['status'] = 1;
        $brandModel = new Brand();
        $reacHeaderBrand = $brandModel -> getBrandDataList($where,'order desc , id desc',1,10);
        $this -> assign('reacHeaderBrand',$reacHeaderBrand);
        //cateName
        $this -> assign('cateName','品牌百科');
        //url
        $modeUrl = request() -> url(true);
        $linkInfo = $this -> getLinkInfo($modeUrl);
        $this -> assign('linkInfo',$linkInfo);
    }

    /*  获取keyword title description
     *  @param      str     'mode'
     *  @return     Array   ['title','keyword','description']
     * **/
    public function getLinkInfo($mode){
        $mode = substr($mode,strpos($mode,"#"));
        $mode = trim($mode,'https://');
        $mode = trim($mode,'http://');
        $mode = trim($mode,'/');
        $where['status'] = 1;
        $where['mode'] = $mode;
        $keywordData = db('keywords') -> where($where) -> find();
        return $keywordData;
    }


}